﻿class Debris
{
    app: QuickApp;
    a1: lighttool.spriteAtlas;
    distance: number;
    angle: number;
    size: number;
    ico: lighttool.sprite;
    doc: MyCoordinates;
    rect: lighttool.spriteRect;

    color: lighttool.spriteColor;

    speed: number;

    constructor(app: QuickApp, a1: lighttool.spriteAtlas)
    {
        this.a1 = a1;
        this.app = app;
        this.rect = new lighttool.spriteRect(0, 0, 0, 0);
        this.color = new lighttool.spriteColor(myColor.r, myColor.g, myColor.b, 0.0);
        this.doc = new MyCoordinates(0, 0);
        this.init();
    }
    init()
    {
        this.doc.x = 0;
        this.doc.y = 0;
        let s = this.a1.sprites["a" + Random(1, 5)];
        this.ico = s;
        this.size = 0;
        this.rect.x = doc.x;
        this.rect.y = doc.y;
        this.rect.w = Random(30, 80);
        this.rect.h = Random(150, 250);

        this.angle = Random(0, 359);
        this.distance = 0;
        this.speed = Random(1, 10);
        this.color.a = 0.0;
    }

    onAnimation()
    {

        this.rect.x = this.app.centerx;
        this.rect.y = this.app.centery;

        if (this.distance == 0 && this.color.a <= (1 - 0.05))
        {
            this.color.a += 0.05;
        } else
        {
            this.distance += (this.speed / 10) + 1;
            if (this.distance >= this.app.centery * 0.4)
            {
                this.color.a -= 0.01;
            }
        }


        let a = TriangleLengthXY(doc, this.angle, this.distance + this.rect.h / 2, this.doc);

        this.rect.h += 0.1;
        this.rect.w += 0.1;
        this.rect.x = a.x;
        this.rect.y = a.y;
        //this.a1.drawByTexture(this.app.sb, this.ico, this.rect, this.color, BiasAngleCount(this.angle + 90));
        this.a1.drawSpriteByTexture(this.app.sb, this.ico,this.rect, this.color, BiasAngleCount(this.angle + 90));
    }
}